﻿using Aop.Api;
using System.Collections.Generic;
using Aop.Api.Request;
using Aop.Api.Response;
using System;
using Aop.Api.Util;
using WeChat.Common;
using System.IO;

namespace WeChat.Common2
{
    public class AlipayApply
    {

        IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", Config.appId, Config.merchant_private_key, "json", "1.0", "RSA2", Config.alipay_public_key, Config.charset, false);
        
        private LogHelper log = new LogHelper(AppDomain.CurrentDomain.BaseDirectory + "/log/log.txt");
        /// <summary>
        /// 上传证件图片，返回图片id
        /// </summary>
        /// <param name="imgName">证件名</param>
        /// <returns></returns>
        public void uploadImg(string imgName, string imgPath)
        {
            AntMerchantExpandImageUploadRequest request = new AntMerchantExpandImageUploadRequest();
            request.ImageType = "png";
            FileItem ImageContent = new FileItem(new FileInfo(imgPath));
            request.ImageContent = ImageContent;

            AntMerchantExpandImageUploadResponse response = client.Execute(request);
            if (response.Msg == "Success")
            {
                log.WriteLine("调用成功");
                log.WriteLine(imgName + ":" + response.ImageId);
            }
            else
            {
                log.WriteLine("调用失败");
                log.WriteLine(imgName + ":" + response.Body);
            }
        }
    }
}
